package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OrdersItem;
import com.ruoyi.system.service.IOrdersItemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单明细Controller
 *
 * @author zhaohs
 * @date 2021-01-04
 */
@Controller
@RequestMapping("/system/orderitem")
public class OrdersItemController extends BaseController {
    private String prefix = "system/orderitem";

    @Autowired
    private IOrdersItemService ordersItemService;

    @RequiresPermissions("system:orderitem:view")
    @GetMapping()
    public String orderitem() {
        return prefix + "/orderitem";
    }

            /**
         * 查询订单明细列表
         */
        @RequiresPermissions("system:orderitem:list")
        @PostMapping("/list")
        @ResponseBody
        public TableDataInfo list(OrdersItem ordersItem) {
            startPage();
            List<OrdersItem> list = ordersItemService.selectOrdersItemList(ordersItem);
            return getDataTable(list);
        }
    
    /**
     * 导出订单明细列表
     */
    @RequiresPermissions("system:orderitem:export")
    @Log(title = "订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrdersItem ordersItem) {
        List<OrdersItem> list = ordersItemService.selectOrdersItemList(ordersItem);
        ExcelUtil<OrdersItem> util = new ExcelUtil<OrdersItem>(OrdersItem. class);
        return util.exportExcel(list, "orderitem");
    }

            /**
         * 新增订单明细
         */
        @GetMapping("/add")
        public String add() {
            return prefix + "/add";
        }
    
    /**
     * 新增保存订单明细
     */
    @RequiresPermissions("system:orderitem:add")
    @Log(title = "订单明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrdersItem ordersItem) {
        return toAjax(ordersItemService.insertOrdersItem(ordersItem));
    }

    /**
     * 修改订单明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        OrdersItem ordersItem =ordersItemService.selectOrdersItemById(id);
        mmap.put("ordersItem", ordersItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单明细
     */
    @RequiresPermissions("system:orderitem:edit")
    @Log(title = "订单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrdersItem ordersItem) {
        return toAjax(ordersItemService.updateOrdersItem(ordersItem));
    }

            /**
         * 删除订单明细
         */
        @RequiresPermissions("system:orderitem:remove")
        @Log(title = "订单明细", businessType = BusinessType.DELETE)
        @PostMapping("/remove")
        @ResponseBody
        public AjaxResult remove(String ids) {
            return toAjax(ordersItemService.deleteOrdersItemByIds(ids));
        }
        }
